package com.atguigu.lease.common.springmvc;

import com.atguigu.lease.common.result.Result;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author:
 * @date:2025/7/8
 * @description: 全局处理异常
 *  1.@ControllerAdvice @RestControllerAdvice 2.定义异常处理的方法即可 @ExceptionHandler(异常类型.class)
 */

@RestControllerAdvice

public class GlobalExceptionHandlers {


    @ExceptionHandler(Exception.class)
    public Result<String> exceptionHandler(Exception e){
        //记录日志
        e.printStackTrace();
        //返回提示
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler(LeaseException.class)
    public Result<String> leaseExceptionHandler(LeaseException e){
        //记录日志
        e.printStackTrace();
        //返回提示
        return Result.fail(e.getCode(),e.getMessage());
    }
}
